home *** CD-ROM | disk | FTP | other *** search
- Path: news.platinum.com!dcmark
- From: dcmark@platinum.com (Mark Juric)
- Newsgroups: comp.lang.c++,comp.os.linux.development.apps,comp.os.linux.misc
- Subject: Are str* functions okay in C++?
- Date: 8 Mar 1996 18:50:40 GMT
- Organization: PLATINUM technology, Inc.
- Message-ID: <4hpvi0$gt6@news.platinum.com>
- NNTP-Posting-Host: ns2-ssn.platinum.com
-
- Hi all,
- I am relatively new to C++ and I'm having a heck of a time porting a C
- program to C++. I have a function that opens a man page and tries to
- determine if it points to another man page. I use strtok and strcpy in the
- function. It works fine under Solaris 2.x, however, under Linux 1.2.x or
- 1.3.x it chokes on a delete[] statement after several hundred iterations.
- Here's the function. It dies under Linux on the delete[] path; statement.
-
- g++: 2.7.2
- libg++: 2.7.1
-
- on all platforms. Is this a problem with my code, or is something else
- going on here?
-
- Notes: mbuf[MAXLINE] is definately big enough
- *entry is definately big enough
-
-
- // Check if the first line is an alias. If so, get directory
- void
- Index::check_alias(char **entry,
- char *f,
- const char *dirname,
- const char *fullpath)
- {
- char mbuf[MAXLINE];
- char *alias, *ta, *path, *path2, *section, *tptr, *comm_name;;
- char *filename = new char[strlen(f)+1];
- static int num = 0;
-
- alias = ta = path = path2 = section = tptr = comm_name = 0;
-
- strcpy(filename,f);
- sprintf(mbuf,"%s/%s/%s",fullpath,dirname,f);
-
- ifstream infile(mbuf);
- if(!infile) error("Can't open manpage",mbuf);
- infile.getline(mbuf,MAXLINE);
-
- alias = new char[strlen(mbuf) + 1];
- strcpy(alias,mbuf);
-
- comm_name = strtok(filename,".");
-
- cout << "alias: " << alias << "\n";
- if((tptr = strstr(alias,".so")) != NULL){
- tptr += strlen(".so "); // Gets, for instance, 'man2/utime.2'
- path = new char[strlen(fullpath) + strlen(tptr) + 2];
-
- sprintf(path,"%s/%s",fullpath,tptr);
- section = strtok(alias,"/");
- section = §ion[strlen(section)-1];
- }
- else{
- sprintf(mbuf,"%s/%s/%s",fullpath,dirname,f);
- path = new char[strlen(mbuf)+1];
-
- strcpy(path,mbuf);
- section = (char *)&dirname[strlen(dirname)-1];
- }
-
-
- // Allocate for comm_name, section, path, 2 spaces and \0
-
- // Need to find an elegant way to check for existance before calling strlen
- path2 = new char[strlen(comm_name) + strlen(section) + strlen(path) + 3];
-
- sprintf(path2,"%s %s %s",comm_name,section,path);
- delete[] path;
-
- cout << "path2 " << path2 << " num " << num++ << "\n";
- strcpy(*entry,(char *)path2);
-
-
- delete[] path2;
- delete[] filename;
-
- }
-
-
- Thanks,
-
-
- -Mark
- __
- juric@platinum.com
-